package filters.push;

import helper.PlanarImageWrapper;

import java.awt.Rectangle;

import javax.media.jai.PlanarImage;

import at.fhv.framework.filter.PassivePushFilter;
import at.fhv.framework.interfaces.Push;

/**
 * The ROIFilter class.
 * 
 * @author Michael Sieber
 */
public class ROIPushFilter extends
		PassivePushFilter<PlanarImageWrapper, PlanarImageWrapper> {

	/**
	 * 
	 * @param source
	 */
	public ROIPushFilter(Push<PlanarImageWrapper> source) {
		super(source);
	}

	/*
	 * {@inheritDoc}
	 */
	@Override
	protected boolean execute(PlanarImageWrapper entity, PlanarImageWrapper data) {
		int width = data.getImage().getWidth();
		int height = new Double(data.getImage().getHeight() * 0.35).intValue();
		Rectangle rectangle = new Rectangle(0, 50, width, height);
		entity.setImage(PlanarImage
				.wrapRenderedImage(data.getImage().getAsBufferedImage(
						rectangle, data.getImage().getColorModel())));
		return true;
	}

	/*
	 * {@inheritDoc}
	 */
	@Override
	protected PlanarImageWrapper createEntity() {
		return new PlanarImageWrapper();
	}
}
